﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CalcWeb
{
    public partial class CalcForm : System.Web.UI.Page
    {
        private static long result = 0;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btt1_Click(object sender, EventArgs e)
        {
            txtResult.Text += 1;
        }

        protected void btt2_Click(object sender, EventArgs e)
        {
            txtResult.Text += 2;
        }

        protected void btt3_Click(object sender, EventArgs e)
        {
            txtResult.Text += 3;
        }

        protected void btt4_Click(object sender, EventArgs e)
        {
            txtResult.Text += 4;
        }

        protected void btt5_Click(object sender, EventArgs e)
        {
            txtResult.Text += 5;
        }

        protected void btt6_Click(object sender, EventArgs e)
        {
            txtResult.Text += 6;
        }

        protected void btt7_Click(object sender, EventArgs e)
        {
            txtResult.Text += 7;
        }

        protected void btt8_Click(object sender, EventArgs e)
        {
            txtResult.Text += 8;
        }

        protected void btt9_Click(object sender, EventArgs e)
        {
            txtResult.Text += 9;
        }

        protected void btt10_Click(object sender, EventArgs e)
        {
            if (txtResult.Text != "")
                txtResult.Text += 0;
        }

        protected void bttAdd_Click(object sender, EventArgs e)
        {
            result += long.Parse(txtResult.Text);
            txtResult.Text = "";
            txtOper.Text = "+";
        }

        protected void bttMinus_Click(object sender, EventArgs e)
        {
            result -= long.Parse(txtResult.Text);
            txtResult.Text = "";
            txtOper.Text = "-";
        }

        protected void bttMulti_Click(object sender, EventArgs e)
        {
            result *= long.Parse(txtResult.Text);
            txtResult.Text = "";
            txtOper.Text = "x";
        }

        protected void bttDiv_Click(object sender, EventArgs e)
        {
            result /= long.Parse(txtResult.Text);
            txtResult.Text = "";
            txtOper.Text = "/";
        }

        protected void bttResult_Click(object sender, EventArgs e)
        {
            switch (txtOper.Text)
            {
                case "+":
                    result += long.Parse(txtResult.Text);
                    break;
                case "-":
                    result -= long.Parse(txtResult.Text);
                    break;
                case "x":
                    result *= long.Parse(txtResult.Text);
                    break;
                case "/":
                    result /= long.Parse(txtResult.Text);
                    break;
                default:
                    break;
            }
            txtResult.Text = result.ToString();
            txtOper.Text = "";
            result = 0;
        }

        protected void bttCE_Click(object sender, EventArgs e)
        {
            txtResult.Text = "";
            txtOper.Text = "";
        }

        protected void bttDel_Click(object sender, EventArgs e)
        {
            String str = txtResult.Text.Remove(txtResult.Text.Length - 1);
            txtResult.Text = str;
        }
    }
}